import { Injectable } from '@angular/core';
import { Resolve, ActivatedRoute, ActivatedRouteSnapshot } from '@angular/router';
import { WebMessage, WebMessageService, WebMessageTo, WebMessageStatus } from './web-message.service';

@Injectable({
	providedIn: 'root',
})
export class WebMessageDetailService implements Resolve<any> {
	constructor(private webMessageService: WebMessageService) {}
	async resolve(route: ActivatedRouteSnapshot) {
		const id = Number(route.queryParamMap.get('id'));
		const status = route.paramMap.get('status') as WebMessageStatus;
		if (status !== WebMessageStatus.Sent) {
			const message = await this.webMessageService.get(id);
			const brother = await this.webMessageService.brothers(id);
			return { message, brother };
		} else {
			const message = await this.webMessageService.sent.get(id);
			return { message };
		}
	}
}
